package com.ttit.helloworld.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.ttit.helloworld.R;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

public class MButton extends Button implements LifecycleObserver, View.OnClickListener {


    public MButton(Context context) {
        super(context);
    }

    public MButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.e("ttit", "MButton ://////onTouchEvent event ="+event.getAction());
        return super.onTouchEvent(event);
     //   return false;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.e("ttit", "MButton ://////dispatchTouchEvent");
        return super.dispatchTouchEvent(event);
    }

    @Override
    public void onClick(View v) {
        Log.e("ttit","MButton--onClick--");
        switch (v.getId()){
            case R.id.btn:  Log.e("ttit","MButton--onClick--R.id.btn");
            break;
        }
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    void onResume(){
        //启动动画
        Log.e("ttit","MButton--onResume");
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    void onPause(){
        //取消动画
        Log.e("ttit","MButton--onPause");
    }
}
